package com.xyh.config;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;

public class TimeoutCommand extends HystrixCommand<String> {


    public TimeoutCommand() {
        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
        .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
          .withExecutionTimeoutInMilliseconds(2000)));

    }
    @Override
    protected String getFallback() {
        System.out.println("执行回退方法");
        return "fall back";
    }
    protected String run() throws Exception {
        Thread.sleep(3000);
        System.out.println("执行命令");
        return "sucess";
    }
}
